MAPS
Photo by Muhammadtaha Ibrahim Ma’aji on Unsplash
When you get a mobile phone it is almost like having a card to get out of poverty in a couple of years…
— Muhammad Yunus, 2006 Nobel peace prize
df <- read.csv("archetypes/mobile.csv", header = TRUE, encoding="UTF-8")
df
df_wrangle <- df %>%
filter(continent == "Africa", year >= 2000) %>%
# Using countrycode function (from contrycode library) to enrich the dataset with country's ISO2 code
mutate(iso2 = countrycode(code,
origin = "iso3c",
destination = "iso2c")) %>%
select(entity, year, mobile_subs, iso2) %>%
filter(!is.na(iso2))
df_wrangle
# df_countries_grid1 comes from geofacet library
df_grid <- africa_countries_grid1 %>%
mutate(name = case_when(name == "Central African Republic" ~ "CAF",
name == "Republic of the Congo" ~ "COG",
name == "Democratic Republic of the Congo" ~ "COD",
name == "Equatorial Guinea" ~ "GNQ",
name == "São Tomé and Principe" ~ "STP",
TRUE ~ name)) %>%
mutate(code = case_when(name == "Namibia" ~ "NA",
TRUE ~ code))
df_grid
theme_opts <- theme(
text = element_text(family = "inconsolata", size = 16),
plot.title = element_text(color = "#E8EADC", size = 24, face = "bold", hjust=0.5,
margin=margin(30,0,10,0)),
plot.subtitle = element_text(color = "#E8EADC", size = 20, face = "bold", hjust=0.5,
margin=margin(0,0,60,0)),
plot.caption = element_text(color = "#E8EADC", size = 10, face = "bold", hjust=0.5,
margin=margin(30,0,30,0)),
plot.background = element_rect(fill = "#1E1D23"),
strip.background = element_blank(),
strip.text = element_text(color = "#E8EADC", size = 14, face = "bold"),
panel.background = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
axis.text = element_text(size = 7, color = "#E8EADC"),
axis.title.x = element_blank()
)
v1 <- ggplot(df_wrangle) +
geom_rect(aes(xmin = 2000, ymin = 0, xmax = 2017, ymax = 200), fill = "#26262E") +
geom_area(aes(year, mobile_subs), fill = "#008080") +
# Map code with iso2 column in main dataframe to create the facet grid
facet_geo( ~ iso2, grid = df_grid, label = "name") +
scale_x_continuous(breaks = seq(2000, 2015, by = 5), labels = c("'00", "'05", "'10", "'15")) +
labs(title = "African Mobile Phone Subscriptions, 2000-2017",
subtitle = "Mobile subscriptions per 100 people",
caption = NULL) +
theme_opts
girafe(ggobj = v1, width_svg = 12, height_svg = 16,
options = list(opts_sizing(rescale = TRUE, width = 0.7))
)